{extend name="common/base"/}
{block name="style"}
  <link rel="stylesheet" href="{__JS__}/module/dtree/dtree.css">
  <link rel="stylesheet" href="{__JS__}/module/dtree/font/dtreefont.css">
{/block}
<!-- 主体 -->
{block name="body"}
<form class="layui-form body-content">
	<h3 class="h3-title">审核人配置</h3>
	{if condition="$id eq 0"}
	<table class="layui-table">
		<tr>
			<td class="layui-td-gray2">审核类型<font>*</font></td>
			<td>
				<select name="type" lay-verify="required" lay-reqText="请审核类型">
					<option value=""></option>
					<option value="1">报销审核</option>
					<option value="2">报销打款确认</option>
					<option value="3">发票审核</option>
					<option value="4">发票开票</option>
				  </select>
			</td>
			<td class="layui-td-gray2">审核人<font>*</font></td>
			<td>
				<input type="hidden" name="uid" value=""/>
				<input type="text" name="name" readonly autocomplete="off" placeholder="请选择审核人" lay-verify="required" lay-reqText="请选择审核人" class="layui-input" value="">			
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray2" style="vertical-align: top;">备注信息</td>
			<td colspan="3">
				<textarea name="remark" placeholder="请输入备注" class="layui-textarea"></textarea>
			</td>
		</tr>
	</table>
	{else/}
	<table class="layui-table layui-table-form">
		<tr>
			<td class="layui-td-gray2">审核类型<font>*</font></td>
			<td>
				<select name="type" lay-verify="required"  lay-reqText="请审核类型">
					<option value=""></option>
					<option value="1" {eq name="$detail.type" value="1"}selected{/eq}>报销审核</option>
					<option value="2" {eq name="$detail.type" value="2"}selected{/eq}>报销打款确认</option>
					<option value="3" {eq name="$detail.type" value="3"}selected{/eq}>发票审核</option>
					<option value="4" {eq name="$detail.type" value="4"}selected{/eq}>发票开票</option>
				  </select>
			</td>
			<td class="layui-td-gray2">审核人<font>*</font></td>
			<td>
				<input type="hidden" name="uid" value="{$detail.uid}"/>
				<input type="text" name="name" readonly autocomplete="off" placeholder="请选择审核人" lay-verify="required" lay-reqText="请选择审核人" class="layui-input" value="{$detail.name}">			
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray2" style="vertical-align: top;">备注信息</td>
			<td colspan="3">
				<textarea name="remark" placeholder="请输入备注" class="layui-textarea">{$detail.remark}</textarea>
			</td>
		</tr>
	</table>
	{/if}
	<div style="padding: 10px 0">
		<input type="hidden" name="id" value="{$id}" />
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	</div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	function init(layui) {
		var form = layui.form
			, employeepicker = layui.employeepicker
			, layer = layui.layer;			
			
		//添加人员		
		function addEmployee(){
			var ids=$('[name="uid"]').val(),names=$('[name="name"]').val(),idsArray=[],namesArray=[];
			if(ids!=''){
				idsArray=ids.split(',');
				namesArray=names.split(',');
			}
			employeepicker.init({
				department_url: "/home/api/get_department_tree",
				employee_url: "/home/api/get_employee",
				ids:idsArray,
				names:namesArray,
				type:0,
				callback:function(ids,names){
					$('[name="uid"]').val(ids),
					$('[name="name"]').val(names);
				}
			});
		}	
		//选择对应人
		$('[name="name"]').on('click',function(){
			addEmployee();
		});
		//监听提交
		form.on('submit(webform)', function (data) {
			$.ajax({
				url: "/home/check/add",
				type: 'post',
				data: data.field,
				success: function (e) {
					if (e.code == 0) {
						layer.confirm('保存成功,返回列表页吗?', { icon: 3, title: '提示' }, function (index) {
							parent.location.reload();
						});
					} else {
						layer.msg(e.msg);
					}
				}
			})
			return false;
		});
	}

</script>
{include file="common/layui" base="base" extend="['employeepicker']" callback="init" /}
{/block}
<!-- /脚本 -->